<?php
header("content-type:text/html;charset=utf-8");
include "../../public/config/config.php";
$work="active";

if($_POST['to_sms'] == "to_sms"){
	$statusStr = array(
		"0" => "短信发送成功",
		"-1" => "参数不全",
		"-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
		"30" => "密码错误",
		"40" => "账号不存在",
		"41" => "余额不足",
		"42" => "帐户已过期",
		"43" => "IP地址限制",
		"50" => "内容含有敏感词"
	);	
	$smsapi = "http://www.smsbao.com/"; //短信网关
	$user = "18064008959"; //短信平台帐号
	$pass = md5("lll37575451"); //短信平台密码
	$content=$_POST['content'];//要发送的短信内容
	$phone = $_POST['tel'];
	$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
	$result =file_get_contents($sendurl);
//	echo $statusStr[$result];
	echo "<script>alert('".$statusStr[$result]."');</script>";
}

?>
<html lang="zh-CN">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
	<title>我的工作 -- <?php echo $cfg_indexname;?></title>
	
	<!-- Bootstrap -->
	<link href="/public/css/bootstrap.min.css" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="/public/css/main.css"/>
	<style type="text/css">
.wdiy{
	width: 300px;
	display: inline-block;
}

	</style>
	
	<!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
	<!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
	<!--[if lt IE 9]>
	<script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
	<script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
	<![endif]-->
</head>
<body>
<?php include "../../public/include/head.php";?>
<div class="container">
	<ol class="breadcrumb bg_eee">
		<li><a href="/index.php">首页</a></li>
		<li><a href="../">我的工作</a></li>
		<li class="active">网页短信</li>
	</ol>
	<h3 class="text-center bg-primary lhei">康承贝健 -- 网页短信</h3>
	<ul class="nav nav-pills">
	    <li class="active"><a href="#dxyz" data-toggle="tab">短信验证</a></li>
	   	<li><a data-toggle="tab" href="#dxfs">短信发送</a></li>
    	
	</ul>
	<hr />
	<div class="tab-content min_hei">
		<!--伟创聚赢-->
	    <div class="tab-pane active" id="dxyz">
	    	<h3>网页短信&gt;&gt;短信验证</h3><br />
	    	<div class="row">
				<form action="index.php" method="post" class="form-horizontal form_pad" name="frm" onsubmit="return check()" >
				  	<div class="form-group">
					    <label for="input_1" class="col-sm-2 control-label font_s_reg">账号昵称：</label>
					    <div class="col-sm-10">
					      	<input type="text" name="tname" class="form-control wdiy" id="input_1" placeholder="可以是您的姓名...">
					    </div>
				  	</div>
				  	<div class="form-group">
					    <label for="input_2" class="col-sm-2 control-label font_s_reg">手机号码：</label>
					    <div class="col-sm-10">
					      	<input type="text" name="tel" class="form-control wdiy" id="input_2" placeholder="也是注册账号...">&nbsp;&nbsp;&nbsp;
					      	<span id="s_60" class="btn btn-default" onclick="to_sms()">发送验证码</span>
					    </div>
				  	</div>
				  	<div class="form-group">
					    <label for="input_3" class="col-sm-2 control-label font_s_reg">验 证 码 ：</label>
					    <div class="col-sm-10">
					      	<input type="text" name="code2" class="form-control wdiy" id="input_3" placeholder="手机收到的验证码...">
					    </div>
				  	</div>
				  	<div class="form-group">
					    <label for="input_4" class="col-sm-2 control-label font_s_reg">设置密码：</label>
					    <div class="col-sm-10">
					      	<input type="password" name="pwd" class="form-control wdiy" id="input_4" placeholder="设置一个简单好记的密码...">
					    </div>
				  	</div>
				  	<div class="form-group">
					    <label for="input_5" class="col-sm-2 control-label font_s_reg">重复密码：</label>
					    <div class="col-sm-10">
					      	<input type="password" name="pwd2" class="form-control wdiy" id="input_5" placeholder="重复上面的密码...">
					    </div>
				  	</div>
				  	<div class="form-group">
					    <div class="col-sm-offset-2 col-sm-10">
					      	<button type="submit" class="btn btn-info">注册</button>
					    </div>
				  	</div>
				</form>
			</div>
	    	<br /><p>注：这里是模拟客户端注册账号时验证手机号的基本验证功能</p>
	    </div>
	    <!--千硕教育-->
	    <div class="tab-pane" id="dxfs">
	    	<h3>网页短信&gt;&gt;短信发送</h3><br />
	    	<div class="row">
				<form action="index.php" method="post" class="form-horizontal form_pad" name="frm2" onsubmit="return check2()" >
				  	<div class="form-group">
					    <label for="input_22" class="col-sm-2 control-label font_s_reg">手机号码：</label>
					    <div class="col-sm-10">
					    	<input type="hidden" name="to_sms" id="to_sms" value="to_sms" />
					      	<input type="text" name="tel" class="form-control wdiy" id="input_22" placeholder="填写一个手机号...">
					    </div>
				  	</div>
				  	<div class="form-group">
					    <label for="input_23" class="col-sm-2 control-label font_s_reg">编辑短信 ：</label>
					    <div class="col-sm-10">
					    	<textarea name="content" rows="5" cols="" class="form-control wdiy" id="input_23" placeholder="填写要发的短信内容..."></textarea>
					    </div>
				  	</div>
				  	<div class="form-group">
					    <div class="col-sm-offset-2 col-sm-10">
					      	<button type="submit" class="btn btn-info">发送</button>
					    </div>
				  	</div>
				</form>
			</div>
			<br /><p>注：这里是网页里手动填写手机号和短信内容发送短信的功能</p>
	    </div>
	    
	</div>
</div>
<?php include "../../public/include/footer.php";?>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script type="text/javascript" src="/public/js/jquery-3.3.1.min.js"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script type="text/javascript" src="/public/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/public/js/footer.js"></script>

<script type="text/javascript">
var num=120,i,s_60 = document.getElementById("s_60");
var code = "000000";
var ipt_tel;
function numjj(){
	s_60.innerHTML = num+"秒后重新发送...";
	num--;
	if(num == -1){
		s_60.innerHTML = "发送验证码";
		num = 120;
		clearInterval(i);
	}
//	console.log(num);
}
function to_sms(){
	if(s_60.innerHTML == "发送验证码"){
		ipt_tel = document.getElementById("input_2").value;
		//这里要验证是不是合法手机号
		if(!isPhone(ipt_tel)){
			alert("填写正确的手机号才能发验证码！");
		}else{
			s_60.innerHTML = "验证码已发送...";
			$.ajax({
			 	url:"sms.php",
				type:"post",
				data:"tel="+ipt_tel,
				datatype:"json",
				success:function(data){
					code = data;
//					console.log(code);
				}		  	  			  	  			  	  	
			});
	//		console.log(code);
			i = setInterval(numjj,1000);
		}
	}else{
		alert("验证码已经发送！");
	}
}

function isPhone(tel){
	if(tel.length == 11 && tel[0] == 1){
		return true;
	}else{
		return false;
	}
}

function check2(){
	var tel=document.frm2.tel.value;
	if(tel==null || tel==''){
		//这里要验证是不是合法手机号，还要验证是不是刚刚填写的手机号
		alert('手机号码必填！');
		document.frm2.tel.focus();
		return false;
	}else if(!isPhone(tel)){
		alert('请填写正确的手机号！');
		document.frm2.tel.focus();
		return false;
	}
	
	var content = document.frm2.content.value;
	if(content == null || content == ''){
		alert("短信内容必填！");
		document.frm2.content.focus();
		return false;
	}
}

function check(){
	var tname=document.frm.tname.value;
	if(tname==null || tname==''){
		alert('姓名必须填写！');
		document.frm.tname.focus();
		return false;
	}
	
	var tel=document.frm.tel.value;
	if(tel==null || tel==''){
		//这里要验证是不是合法手机号，还要验证是不是刚刚填写的手机号
		alert('手机号码必填！');
		document.frm.tel.focus();
		return false;
	}else if(!isPhone(tel)){
		alert('请填写正确的手机号！');
		document.frm.tel.focus();
		return false;
	}else if(tel != ipt_tel){
		alert("提交的手机号不是刚刚验证的手机号！");
		document.frm.tel.focus();
		return false;
	}
	
	var code2=document.frm.code2.value;
	if(code2==null || code2=='' || code != code2){
		alert('必须填写正确的验证码！');
		document.frm.code2.focus();
		return false;
	}
	
	var pwd=document.frm.pwd.value;
	if(pwd==null || pwd==''){
		alert('密码必须设置！');
		document.frm.pwd.focus();
		return false;
	}
	
	var pwd2=document.frm.pwd2.value;
	if(pwd2==null || pwd2==''){
		alert('重复密码不能为空！');
		document.frm.pwd2.focus();
		return false;
	}
	
	if(pwd != pwd2){
		alert("两次密码不一致！");
		document.frm.pwd.focus();
		return false;
	}
	
	alert("OK!验证成功！");
	return true;
}
</script>

</body>
</html>